package com.wayz.common;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.File;

import static com.wayz.utils.JsonTool.getStr;


@Order(value = 2) // 加载顺序，值越小，优先级越高
@Slf4j
@Component
public class TaskRun implements CommandLineRunner {
    @Override
    public void run(String... args) {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>SpringBoot project已启动");
        String path = "E:\\storage\\json\\target.json";
        File file = new File(path);
        String str = getStr(file);
        JSONObject minTag = JSONObject.parseObject(str);
//        String type = (String) minTag.get("type");
//        log.info("Type: {}",type);
        JSONArray features = minTag.getJSONArray("features");
        for (Object item : features) {
            JSONObject date = (JSONObject) item;
//            String type = (String) date.get("type");
//            log.info("类型为: {}",type);
            JSONObject geometry = date.getJSONObject("geometry");
            JSONArray coordinates = (JSONArray) geometry.get("coordinates");
            log.info("内层数组类型: {}",coordinates.get(0));
        }
    }
}
